﻿/*
* ==============================================================================
*
* Filename: call_sipaccount_util
* Description: call_sipaccount_util
*
* Version: 1.0
* Created: 2020/8/31 14:42:06
* Compiler: Visual Studio 2019
*
* Author: Administrator
* Company: freelancer
*
* ==============================================================================
*/

namespace db_util {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Threading.Tasks;
	using db_model;
	using MySql.Data.MySqlClient;

	public class call_sipaccount_util {
		public static call_sipaccount_model GetModel(string unique_id) {
			var model = new call_sipaccount_model();
			string sql = "select id,unique_id,display_name,name,password,auth_name,svr_ip,svr_port,local_ip,local_port,domain,proxy_svr,express,rtp_codec,rtp_ip,rtp_port,enable,is_use from call_sipaccount where unique_id=?unique_id limit 1";
			MySqlParameter[] parameters = {
	 new MySqlParameter("?unique_id", MySqlDbType.VarChar,36)
				};
			parameters[0].Value = unique_id;
			using (var dr = mysql_helper.GetDataReader(sql, parameters)) {
				if (dr.Read()) {
					model.id = int.Parse(dr["id"].ToString() == "" ? "-1" : dr["id"].ToString());
					model.unique_id = dr["unique_id"].ToString();
					model.display_name = dr["display_name"].ToString();
					model.name = dr["name"].ToString();
					model.password = dr["password"].ToString();
					model.auth_name = dr["auth_name"].ToString();
					model.svr_ip = dr["svr_ip"].ToString();
					model.svr_port = int.Parse(dr["svr_port"].ToString() == "" ? "-1" : dr["svr_port"].ToString());
					model.local_ip = dr["local_ip"].ToString();
					model.local_port = int.Parse(dr["local_port"].ToString() == "" ? "-1" : dr["local_port"].ToString());
					model.domain = dr["domain"].ToString();
					model.proxy_svr = dr["proxy_svr"].ToString();
					model.express = int.Parse(dr["express"].ToString() == "" ? "-1" : dr["express"].ToString());
					model.rtp_codec = dr["rtp_codec"].ToString();
					model.rtp_ip = dr["rtp_ip"].ToString();
					model.rtp_port = int.Parse(dr["rtp_port"].ToString() == "" ? "-1" : dr["rtp_port"].ToString());
					model.enable = int.Parse(dr["enable"].ToString() == "" ? "-1" : dr["enable"].ToString());
					model.is_use = int.Parse(dr["is_use"].ToString() == "" ? "-1" : dr["is_use"].ToString());
				}
			}
			return model;
		}

	}
}